﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using TrabalhoLAP.DAO;

namespace TrabalhoLAP.Controller
{
    public class MaintainItem
    {
        public ArrayList consultarItem(string drcItem, int codItem, int codCategoria, string drcCategoria, string statusRegistro)
        {
            ItemDAO dao = new ItemDAO();
            DataSet ds = new DataSet();

            ArrayList Itens = new ArrayList();

            ds = dao.consultarItem(drcItem, codItem, codCategoria, drcCategoria, statusRegistro);

            if (ds == null || ds.Tables.Count == 0)
                return Itens;

            foreach (DataRow linha in ds.Tables[0].Rows)
            {
                Item Item = new Item();

                Item.CodItem        = Convert.ToInt32(linha["codItem"].ToString());
                Item.DrcItem        = linha["drcItem"].ToString();

                if (linha["codCategoria"].ToString() != null && !linha["codCategoria"].ToString().Equals(""))
                {
                    Item.CodCategoria = Convert.ToInt32(linha["codCategoria"].ToString());
                }
                
                Item.StatusRegistro = linha["statusRegistro"].ToString().Equals("1") ? true : false;

                Itens.Add(Item);
            }

            return Itens;
        }

        public bool atualizarItem(int codItem, string drcItem, string statusRegistro)
        {
            ItemDAO dao = new ItemDAO();
            return dao.alterarItem(drcItem, codItem, statusRegistro);
        }

        public bool cadastrarItem(string drcItem, string statusRegistro)
        {
            ItemDAO dao = new ItemDAO();
            return dao.cadastrarItem(drcItem, statusRegistro);
        }

        public bool atualizarCategoria(int codItem, int codCategoria)
        {
            ItemDAO dao = new ItemDAO();
            return dao.alterarCategoriaItem(codItem, codCategoria);
        }
    }
}